/*     */ package com.zimbra.cs.filter;
/*     */ 
/*     */ import com.zimbra.cs.extension.ExtensionUtil;
/*     */ import java.util.concurrent.ConcurrentMap;
/*     */ import org.apache.jsieve.CommandManager;
/*     */ import org.apache.jsieve.ExecutableCommand;
/*     */ import org.apache.jsieve.exception.LookupException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ZimbraCommandManagerImpl
/*     */   implements CommandManager
/*     */ {
/*     */   private final ConcurrentMap<String, String> classNameMap;
/*     */   
/*     */   public ZimbraCommandManagerImpl(ConcurrentMap<String, String> classNameMap)
/*     */   {
/*  43 */     this.classNameMap = classNameMap;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private Class lookup(String name)
/*     */     throws LookupException
/*     */   {
/*  57 */     Class cmdClass = null;
/*     */     try {
/*  59 */       cmdClass = getClass().getClassLoader().loadClass(getClassName(name));
/*     */     }
/*     */     catch (ClassNotFoundException e)
/*     */     {
/*     */       try {
/*  64 */         cmdClass = ExtensionUtil.loadClass(name, getClassName(name));
/*     */       } catch (ClassNotFoundException ee) {
/*  66 */         throw new LookupException("Command named '" + name + "' not found.");
/*     */       }
/*     */     }
/*  69 */     if (!ExecutableCommand.class.isAssignableFrom(cmdClass)) {
/*  70 */       throw new LookupException("Class " + cmdClass.getName() + " must implement " + ExecutableCommand.class.getName());
/*     */     }
/*  72 */     return cmdClass;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ExecutableCommand getCommand(String name)
/*     */     throws LookupException
/*     */   {
/*     */     try
/*     */     {
/*  88 */       return (ExecutableCommand)lookup(name).newInstance();
/*     */     } catch (InstantiationException e) {
/*  90 */       throw new LookupException(e.getMessage());
/*     */     } catch (IllegalAccessException e) {
/*  92 */       throw new LookupException(e.getMessage());
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean isCommandSupported(String name)
/*     */   {
/* 105 */     boolean isSupported = false;
/*     */     try {
/* 107 */       lookup(name);
/* 108 */       isSupported = true;
/*     */     }
/*     */     catch (LookupException e) {}
/* 111 */     return isSupported;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected String getClassName(String name)
/*     */     throws LookupException
/*     */   {
/* 126 */     String className = (String)this.classNameMap.get(name.toLowerCase());
/* 127 */     if (null == className) {
/* 128 */       throw new LookupException("Command named '" + name + "' not mapped.");
/*     */     }
/* 130 */     return className;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/filter/ZimbraCommandManagerImpl.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */